package flexulous.view;

/*
 * FlexulousToolPanel.java
 * part of the Flexulous plugin for the jEdit text editor
 * Copyright (C) 2001 Chris Hill
 * jgellene@nyc.rr.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: FlexulousToolPanel.java 12504 2008-04-22 23:12:43Z ezust $
 */

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import org.gjt.sp.jedit.GUIUtilities;
import org.gjt.sp.jedit.jEdit;
import org.gjt.sp.jedit.gui.RolloverButton;

import flexulous.*;

public class FlexulousToolPanel extends JPanel {

	private JLabel label;
	private JButton compileAll;

	public FlexulousToolPanel() {
		setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

		add(makeCustomButton("flexulous.add-target", new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				FlexulousPlugin.getInstance().addTarget();
			}
		}));
		
		compileAll = new JButton("Compile selected");
        compileAll.addActionListener(new CompileAllListener());
        add(compileAll);
	}

	public void propertiesChanged() {
	}

	private AbstractButton makeCustomButton(String name, ActionListener listener) {
		String toolTip = jEdit.getProperty(name.concat(".label"));
		AbstractButton b = new RolloverButton(GUIUtilities.loadIcon(jEdit
				.getProperty(name + ".icon")));
		if (listener != null) {
			b.addActionListener(listener);
			b.setEnabled(true);
		} else {
			b.setEnabled(false);
		}
		b.setToolTipText(toolTip);
		return b;
	}
	
    private class CompileAllListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
           FlexulousPlugin.getInstance().compileSelected();
        }
    }
    
}
